package com.snailhd.controller;

import com.snailhd.common.entity.IResult;
import com.snailhd.common.entity.ResultVO;
import com.snailhd.dto.QueryStockListDTO;
import com.snailhd.entity.Stock;
import com.snailhd.mapper.StockMapper;
import com.snailhd.service.impl.MultiThreadDownloadStockdayHistoryHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author hd
 * @date 2019-12-10 00:45
 */

@RestController
@RequestMapping("stockday")
public class DownloadStockdayHistoryController {

    @Resource
    StockMapper stockMapper;

    @Resource
    MultiThreadDownloadStockdayHistoryHandler multiDownloadHandler;

    @RequestMapping("download/{beginDate}/{endDate}")
    public ResultVO download(@PathVariable("beginDate")String beginDate,
                             @PathVariable("endDate")String  endDate) throws Exception {

        QueryStockListDTO query =QueryStockListDTO.builder().order("code").build();
        List<Stock> list = stockMapper.query(query);
        IResult iResult = multiDownloadHandler.download(list,beginDate,endDate);

        return new ResultVO(iResult);
    }

}
